package v1

import (
	"gin-vue-admin/global"
    "gin-vue-admin/model"
    "gin-vue-admin/model/request"
    "gin-vue-admin/model/response"
    "gin-vue-admin/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

// @Tags Timetable
// @Summary 创建Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "创建Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /timetable/createTimetable [post]
func CreateTimetable(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindJSON(&timetable)
	if err := service.CreateTimetable(timetable); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags Timetable
// @Summary 删除Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "删除Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /timetable/deleteTimetable [delete]
func DeleteTimetable(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindJSON(&timetable)
	if err := service.DeleteTimetable(timetable); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags Timetable
// @Summary 批量删除Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /timetable/deleteTimetableByIds [delete]
func DeleteTimetableByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteTimetableByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags Timetable
// @Summary 更新Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "更新Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /timetable/updateTimetable [put]
func UpdateTimetable(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindJSON(&timetable)
	if err := service.UpdateTimetable(timetable); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags Timetable
// @Summary 用id查询Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "用id查询Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /timetable/findTimetable [get]
func FindTimetable(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindQuery(&timetable)
	if err, retimetable := service.GetTimetable(timetable.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"retimetable": retimetable}, c)
	}
}

// @Tags Timetable
// @Summary 分页获取Timetable列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.TimetableSearch true "分页获取Timetable列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /timetable/getTimetableList [get]
func GetTimetableList(c *gin.Context) {
	var pageInfo request.TimetableSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetTimetableInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}

// @Tags Timetable
// @Summary 用TeacherName查询Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "用TeacherName查询Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /timetable/findTimetableByTeacherName [get]
func FindTimetableByTeacherName(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindQuery(&timetable)
	if err, retimetable := service.GetTimetableByTeacherName(timetable.TeacherName); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"retimetable": retimetable}, c)
	}
}

// @Tags Timetable
// @Summary 用ClassId查询Timetable
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Timetable true "用ClassId查询Timetable"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /timetable/findTimetableByClassId [get]
func FindTimetableByClassId(c *gin.Context) {
	var timetable model.Timetable
	_ = c.ShouldBindQuery(&timetable)
	if err, retimetable := service.GetTimetableByClassId(timetable.ClassId); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"retimetable": retimetable}, c)
	}
}